package com.hsq.androidproject.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.lenovo.androidproject3.R;
import com.hsq.androidproject.entity.find.FindPersonOne;
import com.hsq.androidproject.ui.ImageActivity;

import java.util.List;


/**
 * Created by cuilibao on 2017/3/6.
 */

public class ListViewImgsAdapter extends BaseAdapter {
    private Context context;
    private List<FindPersonOne.TopicBean.PhotoesBean> picUrlsList;

    public ListViewImgsAdapter(Context context, List<FindPersonOne.TopicBean.PhotoesBean> picUrlsList) {
        this.context = context;
        this.picUrlsList = picUrlsList;
    }

    @Override
    public int getCount() {
        return picUrlsList.size();
    }

    @Override
    public Object getItem(int position) {
        return picUrlsList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_list, parent, false);
            holder.imageView = (ImageView) convertView.findViewById(R.id.item_grid_iv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final FindPersonOne.TopicBean.PhotoesBean picUrls = picUrlsList.get(position);
        Glide.with(context).load(picUrls.getThumb()).into(holder.imageView);
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ////////大图
                String bigImg = picUrls.getImage();
                Intent intent = new Intent(context, ImageActivity.class);
                intent.putExtra("bigImg", bigImg);
                context.startActivity(intent);
            }
        });
        return convertView;
    }

    class ViewHolder {
        ImageView imageView;
    }
}
